<?php  
    $month_name = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');  
	if(isset($_POST['check']))
	{	
		header('Expires: 0');
		header('Cache-control: private');
		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header('Content-Description: File Transfer');
		header('Content-Type: application/csv');
		
		$csv = "";
		$current = $_REQUEST['current'];
		$time = $_REQUEST['time'];
		$emis = $_REQUEST['emis'];
		$conductor = $_REQUEST['conductor'];
		$tower = $_REQUEST['tower'];
		$year = $_REQUEST['year'];
		$month = $_REQUEST['month'];
		
		include_once('bsaua_orientation/connection.php');
		include_once('bsaua_orientation/query.php');
		$conn = connection();
		$result = select_data($year, $month);
		
		$fp = fopen('temp.csv', 'w');
		foreach ($result as $fields) 
		{
			fputcsv($fp, $fields);
		}	
		
		exec("IEEE.exe temp.csv ".$current." ".$time." ".$emis." ".$conductor." ".$tower, $output);	
		for($i=0; $i<count($output)-1; $i++)		
		{
			$csv .= $output[$i] . "\n";  // SIngle coutation will not work for newline
		}
		$csv .= $output[$i];
		header('Content-disposition: attachment; filename="temp.csv"');
		echo $csv;
		exit;
		
	}
	function select_data($year, $month)
	{
		$query1 = "select * from  weather_info where year = ".$year. " and month = " .$month;
		$res = Query($query1);
	    $result = Assoc($res);
		return $result;
	}
?>

<!DOCTYPE html>
<title> :: Line Temperature Computation ::</title>
<head>   
</head>
<body>
<form enctype="multipart/form-data" action="test.php" method="POST">
<p>
<input type="hidden" name="check" id="check" value=1 >
Year: &nbsp; <select id="year" name="year"> 
                <?php for($i=2008; $i<=2008; $i=$i+100) {?>
                   <option value="<?php echo $i;?>" >  <?php echo $i;?> </option>          
                <?php }?>       
                 </select>
&nbsp;	
 Month: &nbsp; <select id="month" name="month"> 
<?php for($i=1; $i<=12; $i++) {?>
   <option value="<?php echo $i;?>" >  <?php echo $month_name[$i-1];?> </option>          
<?php }?>       
 </select>
 <br>

 Ampacity: &nbsp; <select id="current" name="current"> 
                <?php for($i=900; $i<=1300; $i=$i+100) {?>
                   <option value="<?php echo $i;?>" >  <?php echo $i;?> </option>          
                <?php }?>       
                 </select>
				 <br>
				 
Time Resolution: &nbsp; <select id="time" name="time"> 
                   <option value="0" > 10 mins </option>          
				   <option value="1" >  1 Hr </option>          
				   <option value="2" >  3 Hrs </option>          
                </select>				 
				<br>
				
Emissivity: &nbsp; <select id="emis" name="emis"> 
   <option value="0" > New Conductor </option>          
   <option value="1" > Old Conductor </option>          
   <option value="2" > Change with time </option>          
</select>				 
<br>                

Conductor Type: &nbsp; <select id="conductor" name="conductor"> 
   <option value="0" > Finch </option>          
   <option value="1" > Cardinal </option>          
   <option value="2" > Condor </option>          
   <option value="3" > Drake </option>          
   <option value="4" > Starling </option>          
</select>		
		 
<br>

Tower Number: &nbsp; <select id="tower" name="tower"> 

   <option value="1" > 1 </option>          
   <option value="2" > 2 </option>          
   <option value="3" > 3 </option>          
   <option value="4" > 4 </option>          
   <option value="5" > 5 </option>          
</select>		
<p>
<div id="msg">
</div>
<p>
<input type="submit" value="Line Temperature" >
</form>
</body>
</html>